import sys,os,json
sys.path.append("..")
import numpy as np
from bs4 import BeautifulSoup
from 查找没用的图片 import listDir,printList
import pandas as pd

def getData1():
    npList = np.array(os.listdir("/Users/wangshuguan/Desktop/四川_完成"))
    datas = []
    for i,x in enumerate(npList):
        data = "/Users/wangshuguan/Desktop/四川_完成/" + x
        with open(data) as f:
            fileContent = f.read()
            soup = BeautifulSoup(fileContent,features="html.parser")
            lis = soup.select(".ssjg-cell ul li")
            for li in lis:
                info = []
                info.append(li.select_one(".gs-name").a.getText())
                xinxi = li.select_one(".gs-xinxi")
                if xinxi is not None:
                    infos = xinxi.span.getText().split("：")
                    if len(infos) > 0 and infos[0] == '法定代表人':
                        info.append(infos[1].strip())
                    else:
                        info.append("")
                else:
                    print(x)
                    info.append("")
                datas.append(info)
        if (i % 1000 == 0):
            print(i)
    
    def save(filename, contents):
          fh = open(filename, 'w', encoding='utf-8')
          fh.write(contents)
          fh.close()
    save("/Users/wangshuguan/Desktop/四川列表.txt", json.dumps(datas,ensure_ascii=False))
# getData1()
with open("/Users/wangshuguan/Desktop/四川列表.txt") as f:
    df = pd.DataFrame(np.array(json.load(f)),columns=["name","user"])
    print(df[df.name == "峨眉山市创新园林绿化有限公司"])